package com.ybkj.daijia.api.weixin.handler.impl;

import com.ybkj.daijia.api.weixin.entity.WxBaseMsgEntity;
import com.ybkj.daijia.api.weixin.entity.WxBaseRespEntity;
import com.ybkj.daijia.api.weixin.entity.WxMsgEventEntity;
import com.ybkj.daijia.server.model.WxLocation;
import com.ybkj.daijia.server.service.WxLocationService;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class WxLocationEventHandler extends AbstractWxEventHandler {

    @Autowired
    private WxLocationService wxLocationService;


    @Override
    public boolean canHandle(WxBaseMsgEntity msg) {

        if (super.canHandle(msg)) {
            if ("location".equals(((WxMsgEventEntity) msg).getEvent().toLowerCase())) {
                return true;
            }
        }

        return false;
    }


    @Override
    public WxBaseRespEntity handleEvent(WxMsgEventEntity msg,
        Map<String, Object> context, WxBaseRespEntity resp) {

        WxLocation wxLocation = new WxLocation();
        wxLocation.setFromUserName(msg.getFromUserName());
        wxLocation.setLatitude(msg.getLatitude());
        wxLocation.setLongitude(msg.getLongitude());
        wxLocationService.save(wxLocation);

        return null;
    }


}
